package main

import (
	"fmt"
	//"math"
	//"time"
)

//作业9 写一个日历表
func main() {
	var y int
	var m int

	fmt.Printf("请输入年份:")
	fmt.Scan(&y)
	fmt.Printf("请输入月份:")
	fmt.Scan(&m)
	/*
		//获取当前星期
		t := time.Now()
		nw := int(t.Weekday())
		ny := int(t.Year())
		nm := int(t.Month())
		//ntemp := math.Abs(ny - y)
		nd += AddDayForYear(ny, nm)
		var d = AddDayForYear(y, m)
		var dtemp = int(math.Abs(float64(nd - d)))
		fmt.Println(d)
		fmt.Println(dtemp)
	*/
	var w int

	w = (1 + 2*m + 3*(m+1)/5 + y + y/4 - y/100 + y/400 + 1) % 7
	/*
		if d < nd {
			if dtemp%7 == 0 {
				w = nw
			} else {
				w = dtemp
			}
		} else {
			if dtemp%7 == 0 {
				w = nw
			} else {
				w = nw + dtemp%7
			}
		}
	*/
	var mdays []int
	for i := 1; i <= GetMonthDay(y, m); i++ {
		var num = w % 7
		if num == 0 {
			num = 7
		}
		mdays = append(mdays, num)
		w++
	}
	//fmt.Println(mdays)
	fmt.Println("一  二  三  四  五  六  日")
	fmt.Println("==========================")
	for i := 0; i < len(mdays); i++ {
		if i == 0 {
			for j := 1; j < mdays[i]; j++ {
				fmt.Print("    ")
			}
		}
		if i < 9 {
			fmt.Print(" ")
		}

		if mdays[i] == 7 {
			fmt.Print(i + 1)
			fmt.Println("")
		} else {
			var num = i + 1
			fmt.Print(num, "  ")
		}
	}
}

/*

func AddDay(year int, month int) int {
	var dtemp = 0
	for i := 1; i <= 12; i++ {
		if i == month {
			break
		}
		dtemp += GetMonthDay(year, i)
	}
	return dtemp
}



func AddDayForYear(year int, month int) int {
	var dtemp = 0
	for i := 0; i <= year; i++ {
		for j := 1; j <= 12; i++ {
			if j == month && i == year {
				break
			}
			dtemp += AddDay(i, j)
		}
	}
	return dtemp
}
*/
func GetMonthDay(year int, month int) int {
	var dtemp int
	switch month {
	case 1, 3, 5, 7, 8, 10, 11:
		dtemp = 31
	case 4, 6, 9, 12:
		dtemp = 30
	case 2:
		dtemp = GetRun(year)
	}
	return dtemp
}
func GetRun(y int) int {
	var day int
	if y%400 == 0 {
		day = 29
	} else if y%4 == 0 && y%100 != 0 {
		day = 29
	} else {
		day = 28
	}
	return day
}
